/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GestionRuta.java
 *
 * Created on 07/02/2011, 08:40:20 AM
 */
package com.catosist.run.application.descripciongasto;

import com.catosist.run.application.Util.MiModelo;
import com.catosist.run.business.gestordescripciongasto.GestorDescripcionGasto;
import com.catosist.run.business.gestorruta.GestorRuta;
import com.catosist.run.services.DescripcionGastoDTO;
import com.catosist.run.services.RutaDTO;
import java.util.Iterator;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Bicho
 */
public class GestionDescripcionGasto extends javax.swing.JFrame {

    /** Creates new form GestionRuta */
    public GestionDescripcionGasto() {
        initComponents();
    }

    public GestionDescripcionGasto(GestorDescripcionGasto gestorDescripcionGasto) {
        initComponents();
        this.gestorDescripcionGastoRuta = gestorDescripcionGasto;
        refresh();
    }

    public void refresh() {
        DefaultTableModel model = new MiModelo();
        model.addColumn("id");
        model.addColumn("Nombre");
        model.addColumn("Tipo");

        List<DescripcionGastoDTO> gestorDescripcionGastoDTOs = gestorDescripcionGastoRuta.getAll();
        for (Iterator<DescripcionGastoDTO> it = gestorDescripcionGastoDTOs.iterator(); it.hasNext();) {
            DescripcionGastoDTO descripcionGastoDTO = it.next();
            model.addRow(descripcionGastoDTO.toArray());
        }
        this.jTable1.setModel(model);
    }

    public int getSelectedIndex() {
        return this.jTable1.getSelectedRow();
    }

    public int getSelectedId() {
        return gestorDescripcionGastoRuta.getIdAtIndex(this.jTable1.getSelectedRow());
    }

    public JPanel getPanel(){
        return  this.jPanel1;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setName("jLabel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(129, 129, 129)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 174, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GestionDescripcionGasto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
    private GestorDescripcionGasto gestorDescripcionGastoRuta;
}
